//
//  XQWelcomeCell.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/2/3.
//

import UIKit

class XQWelcomeCell: UICollectionViewCell {
    
    var nextHandle: (() -> Void)?

    private lazy var imageView = {
       let imageView = UIImageView()
        return imageView
    }()
    
    private lazy var nextBtn = {
        let btn = UIButton(type: .custom)
        btn.backgroundColor = .mainTextColor
        btn.setTitle("Next", for: .normal)
        btn.titleLabel?.font = UIFont .systemFont(ofSize: 20, weight: .medium)
        btn.setTitleColor(.white, for: .normal)
        btn.layer.cornerRadius = 30
        btn.addTarget(self, action: #selector(nextClick), for: .touchUpInside)
        return btn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.makeUI()
        self.makeConstraints()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setImageName(name : String) {
        imageView.image = UIImage(named: name)
    }
    
    func setIsLast(isLast : Bool) {
        self.nextBtn.setTitle(isLast ? "Get started" : "Next", for: .normal)
    }
    
    func makeUI() {
        self.contentView.addSubview(imageView)
        self.contentView.addSubview(nextBtn)
    }
    
    func makeConstraints() {
        self.imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        self.nextBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-73)
            make.left.equalTo(36)
            make.right.equalTo(-36)
            make.height.equalTo(50)
        }
    }
    
    
    @objc private func nextClick() {
        nextHandle?()
    }

    
}
